<?php
//
namespace app\home\controller;

use app\common\model\FavoriteModel;
use app\common\model\ShopDeliveryModel;
use app\common\model\ShopInvoiceModel;
use app\common\model\ShopOrderGoodsModel;
use app\common\model\ShopOrderLogModel;
use app\common\model\ShopOrderModel;
use app\common\model\ShopPaymentModel;
use app\common\model\ShopPromotionAuctionLogModel;
use app\common\model\ShopPromotionCardItemModel;
use app\common\model\ShopPromotionGroupbuyCartModel;
use app\common\model\ShopPromotionGroupbuyModel;
use app\common\model\UserAddressModel;
use app\common\model\UserMemberModel;
use app\common\model\UserModel;
use Endroid\QrCode\QrCode;
use mailer\tp5\Mailer;
use MongoDB\Driver\Exception\Exception;
use think\Db;
use think\Request;
use think\Session;

class UserController extends BaseController
{
    private $uid;
    private $userAddressModel;
    private $userMemberModel;
    private $userModel;
    private $auctionLogModel;
    private $groupBuyModel;
    private $groupBuyCartModel;
    private $deliveryModel;
    private $paymentModel;
    private $couponModel;

    //控制器初始化操作
    public function __construct(Request $request)
    {
        parent::__construct($request);
        if ($this->getMemberUid() <= 0) {
            $url = url('home/Public/userlogin', ['url' => urlencode(get_current_url())]);
            $this->error('请先登录！', $url);
        }
        $this->uid = $this->getMemberUid();
        $this->userAddressModel = new UserAddressModel();
        $this->userInvoiceModel = new ShopInvoiceModel();
        $this->userMemberModel = new UserMemberModel();
        $this->userModel = new UserModel();
        $this->auctionLogModel = new ShopPromotionAuctionLogModel();
        $this->groupBuyModel = new ShopPromotionGroupbuyModel();
        $this->groupBuyCartModel = new ShopPromotionGroupbuyCartModel();
        $this->deliveryModel = new ShopDeliveryModel();
        $this->paymentModel = new ShopPaymentModel();
        $this->couponModel = new ShopPromotionCardItemModel();
    }

    /*
     * 网站首页
     */
    public function index()
    {
        return $this->fetch();
    }

    /**
     * 设置
     */
    public function set()
    {
        return $this->fetch();
    }

    /**
     * 用户中心
     */
    public function userInfo()
    {
        $this->assign('userInfo', $this->userInfo);
        return $this->fetch();
    }

    /*编辑会员信息*/
    public function editInfo()
    {
        if ($this->request->isPost()){
            $data = $this->request->param();
            if (!empty($data)) {
                $data['uid'] = $this->userInfo['uid'];
                $this->userMemberModel->editData($data);
                $this->success('会员信息编辑成功！', url('home/User/userInfo'));
            } else {
                $this->error('会员信息未能更新！');
            }
        }else{
            return $this->fetch();
        }
        return true;
    }

    public function username()
    {
        if ($this->request->isPost()) {
            $data    = $this->request->param();
            if (Session::has('sms')){
                $code=Session::get('sms');
                if ($code['time']+600<time()) {
                    $this->error('短信验证码过期');
                }elseif ($data['code']!==$code['code']){
                    $this->error('短信验证码错误');
                }
            }else{
                $this->error('请先获取短信验证码');
            }
            if ($this->userModel->where('uid',$this->uid)->setField('username',$data['username'])){
                $this->success('手机修改成功，请使用修改后的手机登陆');
            }else{
                $this->error('修改失败，请稍后重试');
            }
        } else {
            return $this->fetch();
        }
    }

    /*修改密码*/
    public function password()
    {
        if ($this->request->isPost()) {
            $password = $this->userModel->where('uid', $this->userInfo['uid'])->value('password');
            $data = $this->request->param();
            if (md5($data['oldpassword']) <> $password) {
                $this->error('原密码输入错误！');
            }
            if (empty($data['newpassword'])) {
                $this->error('新密码不能为空！');
            }
            if ($data['newpassword'] <> $data['confirmpassword']) {
                $this->error('两次输入的密码不一致');
            }
            $data['uid'] = $this->userInfo['uid'];
            $data['password'] = $data['newpassword'];
            $this->userModel->editData($data);
            $this->success('密码修改成功！', url('home/User/index'));
        } else {
            return $this->fetch();
        }
    }

    /**
     * 企业认证
     */
    public function companyInfo()
    {
        return $this->fetch();
    }

    /**
     * 账户安全
     */
    public function security()
    {
        return $this->fetch();
    }

    /**
     * 绑定邮箱
     * @return mixed
     */
    public function bindEmail()
    {
        if ($this->request->isPost()) {
            $data = $this->request->post();
            if (!captcha_check($data['vcode'])) {
                $this->error('验证码错误');
            };
            $text = $this->webConfig['EMAIL'];
            $parm = urlencode(str_encode(json_encode(['uid' => $this->uid, 'email' => $data['email']])));
            $url = url('/home/Public/verifyMail', ['parm' => $parm], true, true);
            $text = str_replace('$$url$$', $url, html_out($text));
            $mailer = Mailer::instance();
            $mailer->from(config('mail.addr'), config('mail.name'))
                ->to($data['email'])
                ->subject($this->webConfig['WEBNAME'] . '邮箱验证')
                ->html($text)
                ->send();
            $this->success('邮件发送成功，请登陆邮箱查看');
        } else {
            return $this->fetch();
        }
    }
    /**
     * 绑定微信
     */
    public function bindWechat()
    {
        if ($this->request->has('code')) {
            $oauth = &load_wechat('Oauth');
            // 执行接口操作
            $result = $oauth->getOauthAccessToken();
            // 处理返回结果
            if ($result === FALSE) {
                $this->error('微信绑定失败');
            } else {
                // SDK实例对象
                $oauth = & load_wechat('Oauth');
                // 执行接口操作
                $result = $oauth->getOauthUserinfo($result['access_token'], $result['openid']);
                // 处理返回结果
                if($result===FALSE){
                    // 接口失败的处理
                    return false;
                }else{
                    $userInfo=$this->userInfo;
                    $userInfo['openid']=$result['openid'];
                    if (empty($userInfo['alias'])){
                        $userInfo['alias']=$result['nickname'];
                    }
                    if (empty($userInfo['sex'])){
                        $userInfo['sex']=$result['sex'];
                    }
                    if (empty($userInfo['headimgurl'])){
                        $userInfo['headimgurl']=$result['headimgurl'];
                    }
                    if ($this->userMemberModel->editData($userInfo)){
                        $this->success('微信绑定成功','/home/user/security');
                    }else{
                        $this->error('微信绑定失败');
                    }
                    // 接口成功的处理
                }
            }
        } else {
            $drvice = is_mobile();
            if ($drvice !== 3) {
                $qrCode = new QrCode();
                $qrCode
                    ->setText(url('/home/user/bindwechat',[],true,true))
                    ->setSize(300)
                    ->setPadding(10)
                    ->setErrorCorrection('high')
                    ->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0])
                    ->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0])
                    ->setLabelFontSize(16)
                    ->setLabelFontPath(ROOT_PATH.'public/home/msyh.ttf')
                    ->setLabel('扫描此二维码在微信端打开')
                    ->setImageType(QrCode::IMAGE_TYPE_PNG);
                ob_end_clean();
                header('Content-Type: ' . $qrCode->getContentType());
                $qrCode->render();
            } else {
                // SDK实例对象
                $oauth = &load_wechat('Oauth');
                $url = url('/home/User/bindWechat', '', true, true);
                // 执行接口操作
                $result = $oauth->getOauthRedirect($url, '', 'snsapi_userinfo');

                // 处理返回结果
                if ($result === FALSE) {
                    $this->error('微信绑定失败');
                } else {
                    $this->redirect($result);
                    // 接口成功的处理
                }
            }
        }

    }

    /*
     * 芯多多订单*/
    public function orderList()
    {
        return $this->fetch();
    }

    /*
    * 芯多多订单
     * */
    public function orderInfo()
    {
        return $this->fetch();
    }

    /*
     * 我的集采*/
    public function groupbuyList()
    {
        if ($this->request->isPost()) {
            $status = $this->request->param('status', 0);
            $page = $this->request->param('page', 1);
            $begin_time = $this->request->param('begin_time', 0);
            $end_time = $this->request->param('end_time', 0);
            $name = $this->request->param('name', 0);
            $list = $this->groupBuyCartModel->getList($this->uid, $status, $page, $begin_time ? strtotime($begin_time) : 0, $end_time ? strtotime($end_time) : 0, $name);
            return $list;
        } else {
            return $this->fetch();
        }
    }

    /*
     * 集采付款
    **/
    public function groupbuyToOrder()
    {
        $cartId = $this->request->param('cart_id', 0);
        $info = $this->groupBuyCartModel->getInfo($this->uid, $cartId);
        if ($info['cart_status'] == 0) {
            $this->error('该集采已经转为普通订单，请转至订单处理', 'home/user/orderList');
        }
        if ($this->request->isPost()) {
            $skuIds[$info['sku_id']] = $info['num'];
            $data = $this->request->post();
            $orderInfo = [
                'order_sn' => rand_number(),
                'site_id' => $info['site_id'],
                'site_name' => $info['site_name'],
                'buyer_uid' => $info['member_uid'],
                'buyer_username' => $this->userInfo['username'],
                'pay_code' => $data['pay_code'],
                'pay_name' => $data['pay_name'],
                'goods_amount' => $info['all_money'],
                'shipping_fee' => $this->deliveryModel->calculateFreight($skuIds, $data['delivery_id'], $info['all_money']),
                'card_key' => 0,
                'card_price' => 0,
                'order_price' => $info['simple_price'],
                'order_pay_point' => 0,
                'order_give_point' => 0,
                'order_status' => 0,
                'shipping_status' => 0,
                'pay_status' => 0,
                'refund_status' => 0,
                'order_message' => $data['message'],
                'order_from' => is_mobile() ? 2 : 1,
                'order_type' => 4,
                'create_time' => time(),
                'delivery_name' => $this->deliveryModel->where('delivery_id', $data['delivery_id'])->value('delivery_name')
            ];
            //处理收货地址
            if ($data['address_id'] > 0) {
                $addressModel = new UserAddressModel();
                $addressInfo = $addressModel->where('address_id', $data['address_id'])->find()->toArray();
                $orderInfo = array_merge($orderInfo, $addressInfo);
                unset($orderInfo['address_id'], $orderInfo['uid'], $orderInfo['is_default']);
            }
            //处理发票信息
            $orderInfo['invoice'] = 0;
            if ($data['inv_id'] > 0) { //发票信息
                $invoiceModel = new ShopInvoiceModel();
                $invoiceInfo = $invoiceModel->find($data['inv_id']);
                if ($invoiceInfo) {
                    $orderInfo['invoice'] = 1;
                    $orderInfo['invoice_info'] = json_encode($invoiceInfo);
                }
            }
            Db::startTrans();
            try {
                //保存主表数据
                $orderModel = new ShopOrderModel();
                $orderModel->save($orderInfo);
                $orderId = $orderModel->getData('order_id');
                //从表数据
                if ($info['give_integral'] == -1) {
                    $givePoint = ceil($info['num'] * $info['simple_price']);
                } else {
                    $givePoint = $info['give_integral'];
                }
                $orderGoodsList = [];
                $orderGoodsList[] = [
                    'order_id' => $orderId,
                    'sku_id' => $info['sku_id'],
                    'goods_id' => $info['goods_id'],
                    'site_id' => $info['sku_id'],
                    'buyer_uid' => $this->uid,
                    'sku_sn' => $info['sku_sn'],
                    'goods_name' => $info['goods_name'],
                    'sku_name' => $info['sku_name'],
                    'goods_unit' => $info['goods_unit'],
                    'goods_thumb' => $info['goods_thumb'],
                    'pay_point' => 0,
                    'give_point' => $givePoint,
                    'goods_price' => $info['goods_price'],
                    'unit_price' => $info['simple_price'],
                    'goods_num' => $info['num'],
                    'pay_price' => $info['num'] * $info['simple_price'],
                    'promotion_id' => $info['promotion_id'],
                    'promotion_type' => $info['promotion_type'],
                ];
                $orderGoodsModel = new ShopOrderGoodsModel();
                $orderGoodsModel->saveAll($orderGoodsList);
                //添加订单日志表
                $orderLogModel = new ShopOrderLogModel();
                $orderLogModel->addOrderLog($this->userInfo['username'], $orderId, 0, 0, 0, "{$this->userInfo['username']}提交了订单！");
                $this->groupBuyCartModel->where('cart_id', $cartId)->setField('cart_status', 0);
                Db::commit();
            } catch (Exception $e) {
                $this->error($e);
            }
            $this->success('付款成功', 'home/user/orderList');
        } else {
            //物流
            $delivery = $this->deliveryModel->where('status', 1)->order('is_default desc')->select();
            //支付方式
            $payment = $this->paymentModel->where('enabled', 1)->order('pay_sort asc')->select();
            $this->assign('info', $info);
            $this->assign('payment', $payment);
            $this->assign('delivery', $delivery);
            return $this->fetch();
        }

    }

    /*
        * 账户信息
         * */
    public function account()
    {
        return $this->fetch();
    }

    /**
     * 加入收藏
     */
    public function favoriteAdd()
    {
        $favoriteModel = new FavoriteModel();
        $channel = $this->request->param('channel/d');
        $infoId = $this->request->param('info_id/d');
        $result = $favoriteModel->addFavorite($this->uid, $channel, $infoId);
        if ($result === false) {
            $this->error($favoriteModel->getError());
        } else {
            $this->success('收藏成功！');
        }
    }

    /**
     * 取消收藏
     */
    public function favoriteDel()
    {
        $infoId = $this->request->param('info_id/d');
        $channel = $this->request->param('channel/d');
        $map['uid'] = $this->userInfo['uid'];
        $map['channel'] = $channel;
        $map['info_id'] = $infoId;
        $favoriteModel = new FavoriteModel();
        if ($favoriteModel->where($map)->delete()) {
            $this->success('取消成功！');
        }
    }

    /**
     * 收藏列表
     */
    public function favoriteList()
    {
        $favoriteModel = new FavoriteModel();
        $channel = $this->request->param('channel/d');
        $map['uid'] = $this->userInfo['uid'];
        $map['channel'] = $channel;
        $infoIds = $favoriteModel->where($map)->column('info_id');
        $list = [];
        if ($infoIds) {
            if ($channel > 0) { //收藏的内容 channel为mid
                $extendQuery['aid'] = ['in', $infoIds];
                $extendSearch['channel'] = $channel;
                $list = cms_page_list($this->siteId, $channel, '0', 12, $extendQuery, $extendSearch);
            }
            /*  if ($channel == -2) { //收藏的店铺
                  $extendQuery['aid']      = ['in', $infoIds];
                  $extendSearch['channel'] = $channel;
                  $list                    = cms_page_list('-1', 2, '-1', 12, $extendQuery, $extendSearch);
              }*/
            if ($channel == -1) { //收藏的商品
                $extendQuery['t2.sku_id'] = ['in', $infoIds];
                $extendSearch['channel'] = $channel;
                $list = goods_page_list($this->siteId, '0', 12, $extendQuery, $extendSearch);
            }
        }
        if ($this->request->isPost()){
            if (empty($list)){
                $this->error('内容为空');
            }else{
                return $list;
            }
        }
        $this->assign('list', $list);
        $this->assign('channel', $channel);
        return $this->fetch();
    }

    /*
       * 收货地址列表
    */
    public function addressList()
    {
        $uid = $this->userInfo['uid'];
        $list = $this->userAddressModel->where('uid', $uid)->order('is_default desc')->paginate();
        if ($this->request->isAjax()) {
            $list = obj2array($list, ['address_text']);
            foreach ($list as $k => $v) {
                $list[$k]['json'] = json_encode($v);
            }
            return $list;
        }
        $this->assign('list', $list);
        return $this->fetch();
    }

    /**
     * 添加地址
     */
    public function addressAdd()
    {
        if ($this->request->isPost()) {
            $data = $this->request->param();
            $data['uid'] = $this->getMemberUid();
            $result = $this->validate($data, 'UserAddressValidate');
            if (true !== $result) {
                $this->error($result);
            }
            if (empty($data['address_id'])) {
                $this->userAddressModel->addData($data);
            } else {
                $this->userAddressModel->editData($data);
            }
            if ($data['is_default'] == 1) { //设置默认
                $this->userAddressModel->setDefault($this->getMemberUid(), $this->userAddressModel->address_id);
            }
            $this->success('操作成功！', url('home/User/addressList'));
        }
        $addressId=$this->request->get('address_id/d',0);
        if ($addressId){
            $info = $this->userAddressModel->where('address_id', $addressId)->find();
        }else{
            $info=[];
        }
        $this->assign('info',$info);
        return $this->fetch();
    }

    /**
     * 获取地址信息
     * @return array|false|\PDOStatement|string|\think\Model
     */
    public function addressEdit()
    {
        $addressId = $this->request->param('address_id/d');
        $info = $this->userAddressModel->where('address_id', $addressId)->find();
        return $info;
    }

    /**
     * 删除地址
     */
    public function addressDel()
    {
        $addressId = $this->request->param('address_id/d');
        if ($this->userAddressModel->delData($addressId)) {
            $this->success('删除成功！');
        } else {
            $this->error('删除失败！');
        }
    }

    /**
     * 设置默认收货地址
     */
    public function addressDefault()
    {
        $addressId = $this->request->param('address_id');
        $this->userAddressModel->setDefault($this->getMemberUid(), $addressId);
        $this->success('设置成功！');
    }

    /**
     * 添加发票信息
     */
    public function invoiceadd()
    {
        if ($this->request->isPost()) {
            $data = $this->request->param();
            $data['member_uid'] = $this->userInfo['uid'];
            if ($data['inv_state'] == 2) {
                $map = [];
                $map['member_uid'] = $this->userInfo['uid'];
                $map['inv_state'] = 2;
                $invInfo = $this->userInvoiceModel->where($map)->find();
                if (!empty($invInfo)) {
                    $this->error('专票资质认证只允许提交一次，如需修改请联系客服人员！');
                }
            }
            if (empty($data['inv_title'])) {
                $this->error('发票抬头必须填写');
            }
            if (empty($data['inv_code'])) {
                if ($data['inv_type'] <> 1) {
                    $this->error('纳税人识别号必须填写');
                }
            }
            if ($data['inv_state'] == 2) {
                if (empty($data['inv_info']['inv_reg_bank'])) {
                    $this->error('请填写基本户开户银行');
                }
                if (empty($data['inv_info']['inv_reg_account'])) {
                    $this->error('请填写基本户账号');
                }
                if (empty($data['inv_info']['inv_reg_addr'])) {
                    $this->error('请填写企业注册地址');
                }
                if (empty($data['inv_info']['inv_reg_phone'])) {
                    $this->error('请填写企业营业电话');
                }
                if (empty($data['inv_info']['inv_file'])) {
                    $this->error('请上传加盖公章的营业执照复印件');
                }
            }

            if (empty($data['inv_info']['addr_consignee'])) {
                $this->error('收票人必须填写');
            }
            if (empty($data['inv_info']['addr_tel'])) {
                $this->error('收票人联系电话必须填写');
            }
            if (empty($data['inv_info']['addr_address'])) {
                $this->error('发票邮寄地址必须填写');
            }
            $this->userInvoiceModel->addData($data);
            $this->success('添加成功', url('home/User/invoicelist'));
        }
    }

    /*已开发票列表*/
    public function invoicelist()
    {
        return $this->fetch();
    }

    /*专票信息*/
    public function invoiceinfo()
    {
        /*增值税专用发票只允许设置一个企业信息，更改需联系客服*/
        if ($this->request->isPost()) {
            $data = $this->request->param();
            $data['member_uid'] = $this->userInfo['uid'];
            $result = $this->validate($data, 'UserInvoiceValidate');
            if (true !== $result) {
                $this->error($result);
            }
            if (!empty($data['inv_id'])) {
                $this->userInvoiceModel->editData($data);
            } else {
                $this->userInvoiceModel->addData($data);
            }
            $this->success('操作成功！', url('home/User/invoiceinfo'));
        }
        $map = [];
        $map['member_uid'] = $this->getMemberUid();
        $map['inv_state'] = 2;
        $invInfo = $this->userInvoiceModel->where($map)->find();
        $this->assign('invInfo', $invInfo);
        return $this->fetch();
    }

    /*普票信息*/
    public function commonInvoice()
    {
        if ($this->request->isPost()) {
            $data = $this->request->param();
            $data['member_uid'] = $this->userInfo['uid'];
            $map['inv_title'] = $data['inv_title'];
            $map['inv_state'] = 1;
            $thisInfo = $this->userInvoiceModel->where($map)->find();
            if (!empty($thisInfo)) {
                $this->error('开票信息已存在！');
            } else {
                $this->userInvoiceModel->addData($data);
                $this->success('添加成功', url('home/User/commonInvoice'));
            }
        }
        $map = [];
        $map['member_uid'] = $this->userInfo['uid'];
        $map['inv_state'] = 1;
        $invInfo = $this->userInvoiceModel->where($map)->select()->toArray();
        $this->assign('invInfo', $invInfo);
        return $this->fetch();
    }

    /*获取开票信息*/
    public function getInvinfo()
    {
        $inv_id = $this->request->param('invid/d');
        $invInfo = $this->userInvoiceModel->get($inv_id);
        return $invInfo;
    }

    /*删除开票信息*/
    public function delInvoice()
    {
        $inv_id = $this->request->param('inv_id/d');
        $this->userInvoiceModel->delData($inv_id);
        $this->success('删除成功！', url('commonInvoice'));
    }

    /*优惠券列表*/
    public function coupon()
    {
        $type = $this->request->param('type','unused');
        $map['member_uid'] = $this->userInfo['uid'];
        $couponList = $this->couponModel->getMyCardList($type, $this->userInfo['uid']);
        //dump($couponList);
        if($this->request->isPost()){
            return $couponList;
        }
        $this->assign('type', $type);
        $this->assign('couponList', $couponList);
        return $this->fetch();
    }
    /**
     * 竞拍页面
     * @return mixed
     */
    public function auctionOrderList()
    {
        $uid = $this->userInfo['uid'];
        $list = $this->auctionLogModel->where(['member_uid' => $uid, 'winning' => 1, 'pay_type' => 1, 'status' => 1])->select();
        foreach ($list as $k => $v) {
            $goodsIds[$k] = $v['goods_id'];
            $skuIds[$k] = $v['sku_id'];
            $auctionList[$v['sku_id']] = $v;
            $bond = $this->auctionLogModel->where(['member_uid' => $uid, 'sku_id' => $v['sku_id'], 'pay_type' => 0, 'status' => 1])->value('money');
            $auctionList[$v['sku_id']]['pay'] = $v['money'] - $bond;
            $auctionList[$v['sku_id']]['bond'] = $bond;
        }
        $ma['t1.goods_id'] = ['in', $goodsIds];
        $ma['t2.sku_id'] = ['in', $skuIds];
        $goodsList = '';
        if (!empty($ma)) {
            $goodsList = goods_page_list(-1, -1, $num = 10, $extendQuery = $ma, $extendSearch = $ma, $sort = 'goods_sort desc,create_time desc');
            foreach ($goodsList as $k => $v) {
                $v['acution_info'] = $auctionList[$v['sku_id']];
            }
        }
        $this->assign('goodsList', $goodsList);
        return $this->fetch();
    }

    /**
     * 添加到订单
     * @return mixed
     */
    public function auctionorderadd()
    {
        //物流配送
        $deliveryModel = new \app\common\model\ShopDeliveryModel();
        $delivery = $deliveryModel->where('status', 1)->order('is_default desc')->select();
        $this->assign('delivery', $delivery);
        //支付方式
        $paymentModel = new \app\common\model\ShopPaymentModel();
        $payment = $paymentModel->where('enabled', 1)->order('pay_sort asc')->select();
        $this->assign('payment', $payment);
        //商品信息
        $goodsInfo = $this->request->param();
        $goodsModel = new \app\common\model\ShopGoodsModel();
        $goodsInfo['site_id'] = $goodsModel->where('goods_id', $goodsInfo['goods_id'])->value('site_id');
        $this->assign('goodsInfo', $goodsInfo);
        //竞拍插入订单表
        if ($this->request->has('order_message')) {
            $data = $this->request->param();
            $shopOrderModel = new \app\common\model\ShopOrderModel();
            $orderId = $shopOrderModel->auctionOrder($data['site_id'], $data['sku_id'], $data['address_id'], $data['order_message'], $data['delivery_id'], $data['inv_id'], $payCode = $data['pay_code']);
            if ($orderId > 0) {
                $auctionLogModel = new \app\common\model\ShopPromotionAuctionLogModel();
                if ($auctionLogModel->where(['sku_id' => $data['sku_id'], 'winning' => 1, 'member_uid' => $this->getMemberUid()])->setField(['winning' => 2])) {
                    $this->success('添加成功！', url('index'));
                }
            }
        }
        return $this->fetch();
    }

    /**
     * 退出登录
     */
    public function loginOut()
    {
        cookie('memberDes', null);
        $this->redirect("home/Index/index");
    }
}
